/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.inventory;

import model.inventory.Item;
import utility.com.treeTable.AbstractTreeTableModel;
import utility.com.treeTable.TreeTableModel;

/**
 *
 * @author jay
 */
public class DivisiOrderTM extends AbstractTreeTableModel{
    static protected String[] columnNames = { "PLU", "DIV", "NAMA", "SUPPLIER", "", "" };
    static protected Class<?>[] columnTypes = { TreeTableModel.class, String.class, String.class, String.class, Integer.class, Integer.class};

    private Item data;

    public DivisiOrderTM() {
    }
    
    public DivisiOrderTM(Object root) {
        super(root);
    }
        
    @Override
    public int getColumnCount() {
        return DivisiOrderTM.columnNames.length;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public Class<?> getColumnClass(int column) {
        return columnTypes[column];
    }

    @Override
    public Object getValueAt(Object node, int column) {
        switch (column) {
            case 0: return ((Item) node).getPlu();
            case 1: return ((Item) node).getDivOrder();
            case 2: return ((Item) node).getNama();
            case 3: return ((Item) node).getSupplierName();
            case 4: return ((Item) node).getId();
            case 5: return null;
            default: break;
        }
        return null;
    }

    @Override
    public boolean isCellEditable(Object node, int column) {
        //return column==0 ? true:false;
        return column < 2 ? true:false;
    }

    @Override
    public void setValueAt(Object aValue, Object node, int column) {
        switch (column) {
            case 1: 
                ((Item) node).setDivOrder((String)aValue);
                break;
        }
    }

    @Override
    public Object getChild(Object parent, int index) {
        return ((Item) parent).getChildren().get(index);
    }

    @Override
    public int getChildCount(Object parent) {
        return  ((Item) parent).getChildren().size();
    }
    
}
